package com.thh.design.sington;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @ClassName MyConfig
 * @Description 配置文件类
 *
 * @Author thh
 * @Date 20:34 2021/01/13
 **/
public class MyConfig {
    private static final MyConfig  single= new MyConfig();

    /**
     * 保存配置文件的键值对
     */
    private  Map<String,String> myConfigMap = new HashMap<>();

    private MyConfig(){
        try {
            InputStream in = new FileInputStream("C:\\Users\\King\\Desktop\\java设计模式\\myconfig.txt");
            Properties p = new Properties();
            p.load(in);
            Set<Object> keys = p.keySet();
            Iterator<Object> iterator = keys.iterator();
            while (iterator.hasNext()){
                String key = (String)iterator.next();
                String value = p.getProperty(key);
                myConfigMap.put(key,value);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public  static MyConfig getInstance(){
        return single;
    }

    public String getInfo(String key){
        return myConfigMap.get(key);
    }
}
